<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author Tuyet
 */
class Login extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('my_auth');
        $this->load->library('session');
        $this->load->library('form_validation');
        $this->load->model("m_dangnhap");
        //$this->load->models('m_dangnhap');
    }

    function index() {
        $this->load->view('dangnhap');
    }

    function dangnhap() {
        $user = $this->input->post('username');
        $pass = $this->input->post('password');       
        $dn = new m_dangnhap();
        $a = $dn->check_login($user, $pass);  //$this->m_dangnhap->check_login($u, $p);
        $b = $dn->Layhotenquausername($user, $pass);
        foreach ($b as $c) {
            $MaNguoiDung=$c->MaNguoiDung;
            $HoTen = $c->HoTen;
            $Email = $c->Email;
            $SDT = $c->SDT;
            $DiaChi = $c->DiaChi;
            $MaQuyen = $c->MaQuyen;
            $NgaySinh = $c->NgaySinh;
            $TenDangNhap= $c->TenDangNhap;
        }
        if ($a) {
            $this->session->set_userdata("MaNguoiDung", $MaNguoiDung);
            $this->session->set_userdata("TenDangNhap", $TenDangNhap);
            $this->session->set_userdata("HoTen", $HoTen);
            $this->session->set_userdata("Email", $Email);
            $this->session->set_userdata("SDT", $SDT);
            $this->session->set_userdata("DiaChi", $DiaChi);
            $this->session->set_userdata("MaQuyen", $MaQuyen);
            $this->session->set_userdata("NgaySinh", $NgaySinh);
            header("location: http://localhost:8080/flowershop-424-641/index.php");
            //echo $this->session->userdata("HoTen");
        } else {
            $data['msg'] = "Có Lỗi Trong Quá Trình Đăng Nhập,Quý Khách Vui Lòng Kiểm Tra Lại Username và Password";
            $this->load->view('info_error', $data);
        }
    }

    function dangxuat() {
        $this->session->unset_userdata("MaQuyen");
        $this->session->unset_userdata("MaNguoiDung");
        $this->session->unset_userdata("HoTen");
        $this->session->unset_userdata("Email");
        $this->session->unset_userdata("SDT");
        $this->session->unset_userdata("DiaChi");
        header("location: http://localhost:8080/flowershop-424-641/index.php");
    }

    //put your code here
}
